package com.example.spring.ioc.example;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.example.spring.ioc.example.model.Clazz;
import com.example.spring.ioc.example.model.Student;

/**
 * 
 * @author jiang
 *
 */
public class Example2 {

	public static void main(String[] args) {
		// 通过配置类注册bean, bean定义均在配置类里
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(BeanConfig.class);
		
		// 默认bean id 即类名全小写
		System.out.println(ctx.getBean("clazz"));

		Clazz clazz = ctx.getBean(Clazz.class);
		System.out.println("老师车的名字：" + clazz.getTeacher().getCar().getName());

		Student student = ctx.getBean(Student.class);
		System.out.println(student.say());
		ctx.close();
	}
}
